﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using chessLogic;

namespace chessTest
{
    [TestFixture]
    class testFigure
    {
        private Board board;
        [SetUp]
        public void SetUp()
        {
            board = new Board();
            board.InitialBoard();
        }
        [Test]
        public void testSetNotFigure()
        {
            Figure None = new None();
            Assert.AreEqual(None.Type, FigureType.None);
        }
        [Test]
        public void testSetAllFigure()
        {
            Figure figure = new Pawn(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.Pawn);
            figure = new Bishop(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.Bishop);
            figure = new Rook(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.Rook);
            figure = new Queen(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.Queen);
            figure = new Knight(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.Knight);
            figure = new King(FigureColor.White);
            Assert.AreEqual(figure.Color, FigureColor.White);
            Assert.AreEqual(figure.Type, FigureType.King);
        }
        [Test]
        public void testTypeToChar()
        {
            Figure figure = new Pawn(FigureColor.White);
            Assert.AreEqual('p', figure.TypeToChar());
            figure = new Rook(FigureColor.White);
            Assert.AreEqual('R', figure.TypeToChar());
        }
        [Test]
        public void testEqualsColor()
        {
            Figure figure = new Rook(FigureColor.White);
            Assert.False(figure.EqualsColor(new Rook(FigureColor.Black)));
        }
        [Test]
        public void testEquals()
        {
            Figure figure = new Rook(FigureColor.White);
            Assert.True(figure.Equals(new Rook(FigureColor.White)));
            Assert.False(figure.Equals(new Rook(FigureColor.Black)));
        }
        [Test]
        public void testGetPositionNormalMovePawn()
        {
            List<Position> position = board.getFigure(board.getPosition(1, 4)).GetPossiblyPositionNormalMove(board.getPosition(1, 4), board);
            Assert.AreEqual(position[1].ToString(), "e4");
            position = board.getFigure(board.getPosition(1, 0)).GetPossiblyPositionNormalMove(board.getPosition(1, 0), board);
            Assert.AreEqual(position[1].ToString(), "a4");
        }
        [Test]
        public void testGetPositionTakingMovePawn()
        {
            Position pos = new Position("e4");
            board.setFigure(new Position("e4"),new Pawn(FigureColor.White));
            board.setFigure(new Position("d5"),new Pawn(FigureColor.Black));
            List<Position> position = board.getFigure(pos).GetPossiblyPositionTakingMove(pos, board);
            Assert.AreEqual(position.Count, 1);
            Assert.AreEqual(position[0].ToString(), "d5");
        }
        [Test]
        public void testGetPositionNormalMoveKnight()
        { 
            Position pos = board.getPosition(0, 1);
            List<Position> position = board.getFigure(pos).GetPossiblyPositionNormalMove(pos,board);
            Assert.AreEqual(position.Count, 2);
            Assert.AreEqual(position[0].ToString(), "a3");
        }
        [Test]
        public void testGetPositionTakingMoveKnight()
        {
            Position pos = board.getPosition(0, 1);
            board.setFigure(new Position("c3"), new Pawn(FigureColor.Black));
            List<Position> position = board.getFigure(pos).GetPossiblyPositionTakingMove(pos, board);
            Assert.AreEqual(position.Count, 1);
            Assert.AreEqual(position[0].ToString(), "c3");
        }
        [Test]
        public void testGetPositionNormalMoveRook()
        {
            Position pos = board.getPosition(0, 0);
            board.setFigure(new Position("a2"), new None());
            List<Position> position = board.getFigure(pos).GetPossiblyPositionNormalMove(pos, board);
            Assert.AreEqual(position.Count, 5);
            Assert.AreEqual(position[4].ToString(), "a6");
        }
        [Test]
        public void testGetPositionTakingMoveRook()
        {
            Position pos = board.getPosition(0, 0);
            board.setFigure(new Position("a2"), new None());
            List<Position> position = board.getFigure(pos).GetPossiblyPositionTakingMove(pos, board);
            Assert.AreEqual(position.Count, 1);
            Assert.AreEqual(position[0].ToString(), "a7");
        }
        [Test]
        public void testGetPositionMoveBishop()
        {
            Position pos = board.getPosition(0, 2);
            board.setFigure(new Position("b2"), new None());
            board.setFigure(new Position("d2"), new None());
            List<Position> position = board.getFigure(pos).GetPossiblyPositionNormalMove(pos, board);
            Assert.AreEqual(position.Count, 7);
            position = board.getFigure(pos).GetPossiblyPositionTakingMove(pos, board);
            Assert.AreEqual(position.Count, 0);
        }
        [Test]
        public void testGetPositionMoveQueen()
        {
            Position pos = board.getPosition(0, 3);
            board.setFigure(new Position("c2"), new None());
            board.setFigure(new Position("d2"), new None());
            List<Position> position = board.getFigure(pos).GetPossiblyPositionNormalMove(pos, board);
            Assert.AreEqual(position.Count, 8);
            position = board.getFigure(pos).GetPossiblyPositionTakingMove(pos, board);
            Assert.AreEqual(position[0].ToString(), "d7");
        }
        [Test]
        public void testGetPositionPassantMovePawn()
        {
            board.setFigure(new Position("e5"), new Pawn(FigureColor.White));
            board.setFigure(new Position("d5"), new Pawn(FigureColor.Black));
            List<Position> position = Pawn.GetPossiblyPositionPassantMove(new Position("e5"), board, FigureColor.White);
            Assert.AreEqual(position.Count, 1);
            Assert.True(position[0].Equals(new Position("d6")));
        }
        [Test]
        public void testAddMovesMaked()
        {
            Assert.AreEqual(board.getFigure(new Position("e2")).MovesMaked[0], "e2");
            Assert.AreEqual(board.getFigure(new Position("e2")).MovesMaked.Count, 1);
        }
    }
}
